<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="/demo/html2canvas/html2canvas.min.js"></script>
    <style>
        body {
            margin: 0
        }

        .book {
            width: 750px;
            height: 600px;
            position: absolute;
            background-image: url(/demo/html2canvas/bg.jpg);
            background-repeat: no-repeat;
            background-size: 100%;
        }

        .header {
            display: flex;
            align-items: center;
            padding: 40px;
            color: #fff;
        }

        .header img {
            width: 40px;
        }

        .title {
            font-size: 26px;
            margin-left: 10px;
        }

        .more-content {
            position: absolute;
            bottom: 4%;
        }

        .more-content img {
            width: 260px !important;
            height: 160px;
            margin-right: 10px;
        }

        .more-info-main {
            display: flex;
            background-color: #fff;
            width: 710px;
            margin: 0 20px;
            border-radius: 20px;
            min-height: 200px;
            padding: 30px 20px 30px 30px;
            box-sizing: border-box;
        }

        .more-infos-main {
            display: flex;
            background-color: #fff;
            width: 710px;
            margin: 0 20px;
            border-radius: 20px;
            min-height: 200px;
            padding: 30px 20px 30px 30px;
            margin-bottom: 30px;
            box-sizing: border-box;
        }

        .course-title {
            font-size: 35px;
            color: #000;
            margin: 0 20px;
            width: 400px;
            line-height: 1.3;
            max-height: 130px;
            overflow: hidden;
        }
    </style>
</head>

<body>
    <div class="show" style="max-width: 400px;">
        <img id="image" src="" alt="" width="100%">
    </div>
    <div id="capture" class="book">
        <div class="header">
            <img src="/demo/html2canvas/avatar_default.png">
            <div class="title">学习使用html2canvas</div>
        </div>
        <div class="more-content">
            <div class="more-info-main">
                <img src="/demo/html2canvas/banner.jpg" class="banner">
                <span class="course-title">基于html2canvas实现海报分享</span>
            </div>
        </div>
    </div>
    <script>
        html2canvas(document.querySelector("#capture"), {
            useCORS: true
        }).then(canvas => {
            document.getElementById('capture').style.display = 'none';
            const img = document.getElementById('image');
            img.crossOrigin = "anonymous";
            img.src = canvas.toDataURL("image/png", 1)
        });
    </script>
</body>

</html>